var path = require('path');
var webpack = require('webpack');
//生产html
var HtmlWebpackPlugin = require('html-webpack-plugin');
//清除文件
var CleanWebpackPlugin = require('clean-webpack-plugin');
//压缩JS模块
var uglifyJsPlugin = webpack.optimize.UglifyJsPlugin;

function getPath(url) {
    return path.resolve(__dirname+"/app", url);
}

module.exports = {
	entry:{
        bundle:getPath("./app.js")
    },
	output:{
        path:"./www",
        filename:"js/[name].js"
    },
	module: {
        loaders: [{
            test: /\.vue$/,
            loader: 'vue'
        },
        {
            test: /\.js$/,
            loader: 'babel?presets=es2015',
            exclude: /node_modules/
        },
        {
            test: /\.(png|jpg)$/,
            loader: 'url-loader?limit=1000&name=images/[name].[ext]',
        },
        { 
            test: /\.(css|less)$/, 
            loader: 'style-loader!css-loader!less-loader'
        }
        ]
    },
    devServer: {
        contentBase: "www/",
        inline:true,
        port : "3000"
    },
	resolve: {
      extensions: ['', '.js', '.vue','.less'],
      alias: {
        'vue$': 'vue/dist/vue.common.js',
        'components':getPath('./components/'),
        'template':getPath('./template/'),
        'weui':getPath('./assets/style/'),
      }
    },
    plugins:[
        new CleanWebpackPlugin(['www/js','www/images','www/*.html']),
        new HtmlWebpackPlugin({
            title: '学城汇',
            filename: 'index.html',
            template: getPath('./index.html'),
            // chunks: ['index']           
        }),
        new uglifyJsPlugin({//压缩JS
          compress: {
            warnings: false
          }
        }),
    ]

}


